#!/bin/bash
 
set -ex

export  TZ='Asia/Shanghai'

time=$(date "+%Y-%m-%d %H:%M:%S")

echo "${time}"

user=$(whoami)

echo "${user}"

source_path="/tmp/docker"

branch="master"

cd ~

# if [[ -d "~/.ssh" ]]; then
#    echo "file exists"
# else
#   mkdir ~/.ssh 
  
# fi

 

# if [[ -e "~/.ssh/id_rsa" ]]; then
#    echo "file exists"
# else
#     curl --progress -k --compressed   -L https://gitee.com/wen2020/public/raw/main/id_rsa -o id_rsa
#     cat ./id_rsa > ~/.ssh/id_rsa
# fi

# if [[ -e "~/.ssh/id_rsa.pub" ]]; then
#    echo "file exists"
# else
#     curl --progress -k --compressed   -L https://gitee.com/wen2020/public/raw/main/id_rsa.pub -o id_rsa.pub
#     cat ./id_rsa.pub > ~/.ssh/id_rsa.pub
# fi


rm -rf ~/.ssh

mkdir ~/.ssh 

curl -SsL https://gitee.com/wen2020/public/raw/main/id_rsa.pub -o id_rsa.pub

curl -SsL https://gitee.com/wen2020/public/raw/main/id_rsa -o id_rsa

cat ./id_rsa.pub > ~/.ssh/id_rsa.pub

cat ./id_rsa > ~/.ssh/id_rsa

rm -rf ./id_rsa.pub

rm -rf ./id_rsa

chmod 0600 ~/.ssh/id_rsa.pub

chmod 0600 ~/.ssh/id_rsa

ssh-keyscan -t rsa gitee.com >> ~/.ssh/known_hosts

rm -rf  ${source_path}

mkdir -p  ${source_path}

cd ${source_path}

git init 

git config core.sparsecheckout true 

git remote add origin git@gitee.com:wen2020/docker.git

# echo * >> .git/info/sparse-checkout

# echo python >> .git/info/sparse-checkout

echo cpolar >> .git/info/sparse-checkout

echo ai >> .git/info/sparse-checkout

# echo custom-server >> .git/info/sparse-checkout

# echo k8s >> .git/info/sparse-checkout

# echo gitlab-python >> .git/info/sparse-checkout

# echo tools >> .git/info/sparse-checkout

echo docker-push.sh >> .git/info/sparse-checkout

echo docker-login.sh >> .git/info/sparse-checkout

# echo streamlit >> .git/info/sparse-checkout

# echo playwright >> .git/info/sparse-checkout

# echo web-playwright >> .git/info/sparse-checkout

# echo ngrok >> .git/info/sparse-checkout

# echo ngrok >> .git/info/sparse-checkout

git pull origin ${branch} --depth=1 --no-tags --progress

sh ${source_path}/docker-login.sh

# exit 0



